<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .container{
      background-color: #f00;
    }
    .box{
      width: 100px;
      height: 100px;
      background-color: #0f0;
      float: left;
    }
    
    .clear::after{
      content: "";
      display: block;
      clear: both;
      overflow: hidden;
    }
  </style>
</head>
<body>
  <!-- 浮动后父元素就监听不到高度了 -->
   <div class="container clear">
    <div class="box"></div>
   </div>
</body>
</html>